package com.wiscamp.ninechapters.problems.infrastructure.mappers.collections;

import com.wiscamp.ninechapters.problems.infrastructure.po.collections.CollectionPartPO;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.Collection;

/**
 * 题集试卷部分仓储对象
 *
 * @author yifeng
 */
@Repository
public interface CollectionPartMapper extends JpaRepository<CollectionPartPO, Long>, JpaSpecificationExecutor<CollectionPartPO> {
    /**
     * 通过题集编号和部分编号获取试卷部分
     *
     * @param collectionId
     * @param partId
     * @return
     */
    @Query(value = "select p from CollectionPartPO p where p.collectionId = :collectionId and p.partId = :partId order by p.partId asc, p.partIndex asc")
    CollectionPartPO findPart(long collectionId, long partId);

    /**
     * 通过题集编号获取部分列表
     *
     * @param collectionId
     * @return
     */
    @Query(value = "select p from CollectionPartPO p where p.collectionId = :collectionId order by p.partIndex asc")
    Collection<CollectionPartPO> findListByCollection(long collectionId);
}